<?php
namespace Hive;
/**
 * School Object. 
 * 
 * It represant a School or a university, any scholar etablishment.
 *
 * @author Xavier VILAIN
 * @package hr
 * @property int 	$schoolid			School Id
 * @property string $sch_keyname		Cleanup Name of the School
 * @property string $sch_name			Real Unicode Name
 * @property string $sch_website		School Website
 * @property string $description 		Description
 * @property bool 	$loekz 				Deletion Flag if true is an been deleted
 */
class School extends \Fox\Object\Versioned {
	
	/** 
	 * @param array $fields
	 */
	protected function afterSetFields(array $fields)
	{
		$this->sch_keyname = self::cleanup($fields['sch_name']);
	}
	
	/**
	 * Cleanup School Name (remove accent, convert to lower case...)
	 */
	static function cleanup($schoolName)
	{
		$schoolName = \Fox\Utilities\Text::removeAccents(trim($schoolName));
		return $schoolName;
	}
	
	/**
	 * Check if a school already Exist
	 */
	static function lookup($schoolName)
	{
		$finder = new School();
		$result = $finder->find(new \Fox\Dao\SqlFragment("sch_keyname = ? ", array(self::cleanup($schoolName))));
		if(count($result) > 0)
		{
			return $result[0];
		}
		return false;
	}
}
\Fox\Dao::infos(School::className(),new \Fox\Object\Info('schools', \Fox\Databases::DB_APP));
//\Fox\Dao::useZone(School::className(),new \Fox\Dao\DiskTimeCacheZone(\Fox\Dao\DiskTimeCacheZone::PERIOD_FOREVER,School::cacheDirectory()));